package cm.util;

import java.time.*;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * @program: mklij-user
 * @description: 类的描述
 * @author: zhou.chenyang
 * @create: 2020-06-08 15:04
 */
public class LocalDateUtils {

    public static Date localDateToDate(LocalDate localDate){
        if(null == localDate) {
            return null;
        }

        ZonedDateTime zonedDateTime = localDate.atStartOfDay(ZoneId.systemDefault());
        return Date.from(zonedDateTime.toInstant());
    }
    public static Date localDateToDate(LocalDateTime localDatetime){
        if(null == localDatetime) {
            return null;
        }
        Instant instant = localDatetime.atZone(ZoneId.systemDefault()).toInstant();
        return Date.from(instant);
    }



    public static String localDateFormat(LocalDateTime localDateTime,String format){
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);
        String dateFormat = localDateTime.format(formatter);
        return dateFormat;
    }

    public static LocalDateTime dateToLocalateTime(Date date){
        Instant instant = date.toInstant();
        ZoneId zoneId = ZoneId.systemDefault();

        LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime();

        return localDateTime;
    }
}
